/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author James
 */
@Entity
public class Customer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private String  username;
    private String  password;
    private String  IC; // Can be NRIC or Passport number
    private String  firstName;
    private String  lastName;
    private String  gender;
    private String  address1;
    private String  address2;
    private String  postalCode;
    private String  countryCode;
    private String  phone;
    private String  email;
    private String  country;
    private String  city;
    private String  timezone;
    private int     loyaltyPoints;
    private boolean active;
    private boolean activated;
    private long    birthday;
    private long    registeredDate;
    @OneToMany(cascade={CascadeType.PERSIST}, mappedBy="theCustomer")
    private List<Reservation> listOfReservations;
    @OneToMany(cascade={CascadeType.PERSIST}, mappedBy="theCustomer")
    private List<CustomerTransactions> listOfTransactions;
    @OneToMany(cascade={CascadeType.PERSIST})
    private List<Voucher> listOfVouchers;

    public Customer() {
        this.address1           = "";
        this.address2           = "";
        this.postalCode         = "";
        this.timezone           = "";
        this.loyaltyPoints      = 0;
        this.active             = true;
        this.activated          = false;
        this.registeredDate     = System.currentTimeMillis();
        this.listOfReservations = new ArrayList<Reservation>();
        this.listOfTransactions = new ArrayList<CustomerTransactions>();
        this.listOfVouchers     = new ArrayList<Voucher>();
    }
    
    public void createUser(String username, String password, String IC, String firstName, String lastName, String gender, String countryCode, String phone, String email, String country, String city, long birthday) {
        this.username    = username;
        this.password    = password;
        this.IC          = IC;
        this.firstName   = firstName;
        this.lastName    = lastName;
        this.gender      = gender;
        this.countryCode = countryCode;
        this.phone       = phone;
        this.email       = email;
        this.country     = country;
        this.city        = city;
        this.birthday    = birthday;
    }
    
    public void addReservation(Reservation theReservation) {
        this.listOfReservations.add(theReservation);
    }

    //Getters and Setters
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public List<Reservation> getListOfReservations() {
        return listOfReservations;
    }

    public void setListOfReservations(List<Reservation> listOfReservations) {
        this.listOfReservations = listOfReservations;
    }

    public String getIC() {
        return IC;
    }

    public void setIC(String IC) {
        this.IC = IC;
    }

    public long getBirthday() {
        return birthday;
    }

    public void setBirthday(long birthday) {
        this.birthday = birthday;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public long getRegisteredDate() {
        return registeredDate;
    }

    public void setRegisteredDate(long registeredDate) {
        this.registeredDate = registeredDate;
    }

    public int getLoyaltyPoints() {
        return loyaltyPoints;
    }

    public void setLoyaltyPoints(int loyaltyPoints) {
        this.loyaltyPoints = loyaltyPoints;
    }

    public List<CustomerTransactions> getListOfTransactions() {
        return listOfTransactions;
    }

    public void setListOfTransactions(List<CustomerTransactions> listOfTransactions) {
        this.listOfTransactions = listOfTransactions;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public boolean isActivated() {
        return activated;
    }

    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public List<Voucher> getListOfVouchers() {
        return listOfVouchers;
    }

    public void setListOfVouchers(List<Voucher> listOfVouchers) {
        this.listOfVouchers = listOfVouchers;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (username != null ? username.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Users[ id=" + username + " ]";
    }
    
}
